﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate.Connection;
using System.Data;
using NHibernate.Tool.hbm2ddl;
using NHibernate.Cfg;

namespace InnovTech.Data.NHibernate.SQLiteUtil
{
    public class SQLiteInMemoryDBUtil
    {
        public static void DestroySQLiteInMemeroyDB()
        {
            SQLiteInMemoryConnectionProvider.ExplicitlyDestroyConnection();
        }

        public static Configuration CreateSQLiteInMemeroyDB(params MappingFileAssembly[] mfAssemblies)
        {
            Configuration config = ConfigurationBuilder.GetSQLiteInMemoryConfiguration();
            if (mfAssemblies != null)
            {
                foreach (var mfAssembly in mfAssemblies)
                {
                    config.AddMappingFileAssembly(mfAssembly);
                }
            }
            SchemaExport export = new SchemaExport(config);
            export.Create(false, true);

            return config;
        }

        public static Configuration CreateSQLiteInMemeroyDB(params MappingFile[] mappingFiles)
        {
            Configuration config = ConfigurationBuilder.GetSQLiteInMemoryConfiguration();
            if (mappingFiles != null)
            {
                foreach (var file in mappingFiles)
                {
                    config.AddMappingFile(file);
                }
            }
            SchemaExport export = new SchemaExport(config);
            export.Create(false, true);

            return config;
        }
    }
   
}
